package com.sora.sora.security.authorise.controller;

import com.sora.sora.common.annotation.Auth;
import com.sora.sora.common.model.vo.ResultVO;
import com.sora.sora.common.utils.ResponseResult;
import com.sora.sora.security.authorise.service.ResourcesService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Auth(id = 1000, name = "资源管理")
@Api(value = "资源管理", tags = "资源管理")
@RestController
@RequestMapping("resource")
public class ResourcesController {

    @Resource
    ResourcesService resourcesService;

    @Resource
    ResponseResult responseResult;


    @ApiOperation(value = "获得所有页面")
    @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "int", paramType = "query")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功")
    })
    @GetMapping("/page")
    public ResultVO getAllPage(@RequestParam("uid") int uid) {
        return responseResult.ok(resourcesService.getPageResourcesByUserId(uid));
    }


    @Auth(id = 1, name = "权限管理")
    @ApiOperation(value = "获得所有权限")
    @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "int", paramType = "query")
    @GetMapping
    public ResultVO getAll(@RequestParam("uid") int uid) {
        return responseResult.ok(resourcesService.getResourcesByUserId(uid));
    }
}
